/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.drifter;

/**
 *
 * @author Aaron
 */

public abstract class Entity {
    protected MapCell position;
    protected Map map;

    protected Entity (Map map, MapCell position) {
        this.map = map;
        this.setPosition(position);
    }

    public MapCell getPosition ( ) {
        return this.position;
    }

    public void setPosition (MapCell newPos) {
        if (this.position != null) {
            this.position.removeEntity(this);
        }
        newPos.addEntity(this);
        position = newPos;
    }

    public int getX ( ) {
        return Math.round(this.position.getX());
    }

    public void setX (int x) {
        MapCell potentialPosition = map.getMapCell(x, this.getY());
        if (potentialPosition != null) {
            this.setPosition(potentialPosition);
        }
    }

    public int getY ( ) {
        return Math.round(this.position.getY());
    }

    public void setY (int y) {
        MapCell potentialPosition = map.getMapCell(this.getX(), y);
        if (potentialPosition != null) {
            this.setPosition(potentialPosition);
        }
    }
}
